package com.jmcgg.freesky.common.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class FreeskyUtil {
	private static Logger _logger;

	/**
	 * 取得一个Logger的实例，以方便日志操作
	 * 
	 * @return
	 */
	public static Logger log() {
		if (_logger == null) {
			_logger = Logger.getLogger("freesky");
		}
		return _logger;
	}

	/**
	 * This is the main entry point of all Freesky Utility methods.
	 * 
	 * @param aArgs
	 */
	public static void main(String[] aArgs) {
		CommandLine cmd = new CommandLine();
		cmd.parse(aArgs);
		cmd.validate();
		cmd.run();
	}
}

class CommandLine {
	private String method;
	private List<String> parameters = new ArrayList<String>();
	private boolean isParmValid;

	public void parse(String[] args) {
		if (null != args[0])
			method = args[0];
		for (int i = 1; i < args.length; i++) {
			parameters.add(args[i]);
		}
	}

	public boolean validate() {
		if (method.equalsIgnoreCase("ExcelHelper.parseStandingData")) {
			// tableName, excelFile, resultFile
			return parameters.size() == 3;
		}
		return false;
	}

	public void run() {
		if (method.equalsIgnoreCase("ExcelHelper.parseStandingData")) {
			ExcelHelper helper = new ExcelHelper();
			helper.setExcelFileDir(parameters.get(1));
			helper.parseStandingData(parameters.get(0), parameters.get(2));
		}
	}

}
